$
a[1] =  Event[THIS].Name; // sound name
d[1] =  Event[THIS].Id * 100; // sound ID


========================================================================


$
// VOLUME change
if(d[d[1]+17] >= Math.Rand(1, 100))
  // Spontaneous value change
  d[d[1]+11] = Math.Rand(d[d[1]+13], d[d[1]+14]);
else
  // Regular value change
  if(d[d[1]+18] >= Math.Rand(1, 100))
    // Spontaneous direction change
    if(Math.Rand(0,1) == 1)
      d[d[1]+12] = 1;
    else
      d[d[1]+12] = -1;
    endif;
  else
    // Continuous direction
    if(d[d[1]+12] > 0)
      d[d[1]+11] += Math.Rand(d[d[1]+15], d[d[1]+16]);
    elseif(d[d[1]+12] < 0)
      d[d[1]+11] -= Math.Rand(d[d[1]+15], d[d[1]+16]);
    endif;
    // Check min/max value
    if(d[d[1]+11] < d[d[1]+13])
      d[d[1]+11] = d[d[1]+13];
      d[d[1]+12] = 1; // switch to positive direction
    elseif(d[d[1]+11] > d[d[1]+14])
      d[d[1]+11] = d[d[1]+14];
      d[d[1]+12] = -1; // switch to negative direction
    endif;
  endif;
endif;

$
// TEMPO change
if(d[d[1]+27] >= Math.Rand(1, 100))
  // Spontaneous value change
  d[d[1]+21] = Math.Rand(d[d[1]+23], d[d[1]+24]);
else
  // Regular value change
  if(d[d[1]+28] >= Math.Rand(1, 100))
    // Spontaneous direction change
    if(Math.Rand(0,1) == 1)
      d[d[1]+22] = 1;
    else
      d[d[1]+22] = -1;
    endif;
  else
    // Continuous direction
    if(d[d[1]+22] > 0)
      d[d[1]+21] += Math.Rand(d[d[1]+25], d[d[1]+26]);
    elseif(d[d[1]+12] < 0)
      d[d[1]+21] -= Math.Rand(d[d[1]+25], d[d[1]+26]);
    endif;
    // Check min/max value
    if(d[d[1]+21] < d[d[1]+23])
      d[d[1]+21] = d[d[1]+23];
      d[d[1]+22] = 1; // switch to positive direction
    elseif(d[d[1]+21] > d[d[1]+24])
      d[d[1]+21] = d[d[1]+24];
      d[d[1]+22] = -1; // switch to negative direction
    endif;
  endif;
endif;

$
// BALANCE change
if(d[d[1]+37] >= Math.Rand(1, 100))
  // Spontaneous value change
  d[d[1]+31] = Math.Rand(d[d[1]+33], d[d[1]+34]);
else
  // Regular value change
  if(d[d[1]+38] >= Math.Rand(1, 100))
    // Spontaneous direction change
    if(Math.Rand(0,1) == 1)
      d[d[1]+32] = 1;
    else
      d[d[1]+32] = -1;
    endif;
  else
    // Continuous direction
    if(d[d[1]+32] > 0)
      d[d[1]+31] += Math.Rand(d[d[1]+35], d[d[1]+36]);
    elseif(d[d[1]+12] < 0)
      d[d[1]+31] -= Math.Rand(d[d[1]+35], d[d[1]+36]);
    endif;
    // Check min/max value
    if(d[d[1]+31] < d[d[1]+33])
      d[d[1]+31] = d[d[1]+33];
      d[d[1]+32] = 1; // switch to positive direction
    elseif(d[d[1]+31] > d[d[1]+34])
      d[d[1]+31] = d[d[1]+34];
      d[d[1]+32] = -1; // switch to negative direction
    endif;
  endif;
endif;


========================================================================


$
// Play sound and wait
Command.PlaySound(a[1], d[d[1]+11], d[d[1]+21], d[d[1]+31]);
Command.Wait(Math.Rand(d[d[1]+41], d[d[1]+42]));